<?php
$week = intval($_GPC['week']);
$start = $_GPC['start'];
$date = $_GPC['date'];
$end_time = $_GPC['end_time'];
$goodsid = $_GPC['goodsid'];
$uniacid = $_W['uniacid'];
$openid = $_W['openid'];
$starttime = $date . $start;
$starttime = strtotime($starttime);
//die(json_encode(array('w' => $week, 's' => $start, 'd' => $date, 'g' => $goodsid, 'e' => $end_time,'u'=>$uniacid,'o'=>$openid,'t'=>$starttime)));
$checkorder = pdo_fetch("select * from " . tablename('tg_collect') . " where uniacid = '{$uniacid}' and openid = '{$openid}' and sid = '{$goodsid}' and starttime = '{$starttime}' ");
$is_hexiao_member = 1;
//die(json_encode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']));
if (empty($checkorder)) {
    $is_hexiao_member = 0;
}

if ($_W['ajax']) {
    if (!empty($checkorder) && $checkorder['active_times'] < 1) {
        wl_json(0, '该项目参加次数已用完，无法再次参加');
    }
    die(json_encode(array('id'=>$_GPC['id'],'result'=>$_GPC['result'])));
    if (pdo_update('tg_collect', array('active_times' => ($checkorder['active_times'] - 1)), array('id' => $checkorder['id']))) {
        $data = array();
        $data['uniacid'] = $checkorder['uniacid'];
        $data['cid'] = $checkorder['id'];
        $data['orderno'] = $checkorder['orderno'];
        $data['openid'] = $checkorder['openid'];
        $data['check_openid'] = "self";
        $data['check_time'] = TIMESTAMP;
        pdo_insert('tg_hexiao', $data);
        if ($checkorder['times'] == 1) {
            pdo_update('tg_order', array('status' => 3), array('id' => $checkorder['id']));
        }
        pdo_update('tg_member', array('order_times +=' => 1), array('uniacid' => $checkorder['uniacid'], 'openid' => $checkorder['openid']));
        wl_json(1);
    } else {
        wl_json(0, '核销失败，请重试！');
    }
}
include wl_template('shaoniangongcheck');
exit();